package com.hnhegui.backend.platform.controller.payment;

import com.hnhegui.backend.entity.Result;
import com.hnhegui.backend.platform.service.payment.RestPaymentService;
import com.hnhegui.backend.platform.vo.payment.request.PaymentCallbackRequestVO;
import com.hnhegui.backend.platform.vo.payment.request.PaymentRequestVO;
import com.hnhegui.backend.platform.vo.payment.response.PaymentCallbackResponseVO;
import com.hnhegui.backend.platform.vo.payment.response.PaymentResponseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付Controller
 */
@RestController
@RequestMapping("/rest/payments")
public class RestPaymentController {

    @Autowired
    private RestPaymentService paymentService;

    /**
     * 发起支付
     */
    @PostMapping("/pay")
    public Result<PaymentResponseVO> pay(@Validated @RequestBody PaymentRequestVO request) {
        PaymentResponseVO response = paymentService.initiatePayment(request);
        return Result.success(response);
    }

    /**
     * 支付回调（模拟）
     */
    @PostMapping("/callback")
    public Result<PaymentCallbackResponseVO> paymentCallback(@Validated @RequestBody PaymentCallbackRequestVO request) {
        PaymentCallbackResponseVO response = paymentService.handlePaymentCallback(request);
        return Result.success(response);
    }
}
